#!/usr/bin/python3
#coding=utf-8


import os
import sys
import time
import datetime
import smtplib
from log import CLog
from mysqlDB import CMySqlDB


#服务器ip
host="10.1.54.53"
mysqlPort=3306
dbUser="shengli"
dbPwd="shengli0"

#数据库
configDB="fut_one_config"

todayWeek = datetime.datetime.now().weekday() + 1
today = datetime.datetime.now().strftime('%Y%m%d')
execLog = CLog(logName="remOneAddUserAccount" + today + ".log", isPrint=True)


def popenLog(str = ""):
    os.system(str)
    execLog.log(str)

def changeDBDate():
    configDBInstanceNew = CMySqlDB(log=execLog, dbHost=host, dbPort=mysqlPort, dbName=configDB, dbUser=dbUser, dbPwd=dbPwd)

    # 账户用户
    for i in range(46, 1000):
        #账户是399000+i  例如3966046 插数据的时候需要计算下加多少数据， 建议数据库先备份再开始加数据
        user=3966000+i
        account = str(user)
        # 账户数据t_account_info
        sqlStr = "REPLACE INTO t_account_info (account_id, account_desc, ot_cluster_id, trade_previlege, last_update_time)  \
            VALUES('" + account + "','" + "no use" + "','ot_cluster1', 0, '0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)

        # 交易编码
        sqlStr = "REPLACE INTO t_account_exchange_code(account_id, exchange_id, hedge_flag, exchange_code, last_update_time) \
            VALUES('" + account + "', 102, 2,'" + account + "102" + "','0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)
        sqlStr = "REPLACE INTO t_account_exchange_code(account_id, exchange_id, hedge_flag, exchange_code, last_update_time) \
            VALUES('" + account + "', 103, 2,'" + account + "103" + "','0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)
        sqlStr = "REPLACE INTO t_account_exchange_code(account_id, exchange_id, hedge_flag, exchange_code, last_update_time) \
            VALUES('" + account + "', 104, 2,'" + account + "104" + "','0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)
        sqlStr = "REPLACE INTO t_account_exchange_code(account_id, exchange_id, hedge_flag, exchange_code, last_update_time) \
            VALUES('" + account + "', 105, 2,'" + account + "105" + "','0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)
        sqlStr = "REPLACE INTO t_account_exchange_code(account_id, exchange_id, hedge_flag, exchange_code, last_update_time) \
            VALUES('" + account + "', 106, 2,'" + account + "106" + "','0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)

        # 初始权益
        sqlStr = "REPLACE INTO t_account_balance(account_id, day_init_balance, day_init_equity, last_update_time) \
            VALUES('" + account + "', '100000000.00', '100000000.00', '0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)

        # 用戶信息 * 2
        sqlStr = "REPLACE INTO t_user_info(user_id, login_id, md5_pwd, user_name, enabled, allow_mbl_query, \
                      allow_using_protocol, flowctrl_fusing, fusing_seconds, flowctrl_threshold, \
                      flowctrl_time, last_login_time, subscribe_type, create_time, active_time, last_update) \
        VALUES(" + str(i * 3) + ",'" + (account + "1") + "', 'C4CA4238A0B923820DCC509A6F75849B', '', 'Y', 'N', 'Y', 'Y', 30, 300, 1, \
               '0000-00-00 00:00:00', 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)
        sqlStr = "REPLACE INTO t_user_info(user_id, login_id, md5_pwd, user_name, enabled, allow_mbl_query, \
                              allow_using_protocol, flowctrl_fusing, fusing_seconds, flowctrl_threshold, \
                              flowctrl_time, last_login_time, subscribe_type, create_time, active_time, last_update) \
                VALUES(" + str(i * 3 + 1) + ",'" + (account + "2") + "', 'C4CA4238A0B923820DCC509A6F75849B', '', 'Y', 'N', 'Y', 'Y', 30, 300, 1, \
                       '0000-00-00 00:00:00', 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00');"
        configDBInstanceNew.exec(sqlStr)

        # 账户用户链接
        sqlStr = "REPLACE INTO t_account_user_link (account_id, user_id) VALUES ('" + account +"'," + str(i * 3)+ ");"
        configDBInstanceNew.exec(sqlStr)
        sqlStr = "REPLACE INTO t_account_user_link (account_id, user_id) VALUES ('" + account +"'," + str(i * 3 + 1)+ ");"
        configDBInstanceNew.exec(sqlStr)

changeDBDate()